package com.itheima.job;

import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.OrderSetting;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

public class ClearOrderSetting {
    @Autowired
    private OrderSettingDao dao;

    public void clearOrderSetting(){

        try {
            String s = DateUtils.parseDate2String(new Date());
            List<OrderSetting> orderSettings = dao.getBeforeOrderSetting(s);
            if(orderSettings!=null&&orderSettings.size()>0){
                for (OrderSetting orderSetting : orderSettings) {
                    dao.saveOrderSetting(orderSetting);
                }
                dao.deleteOrderSetting(s);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
